﻿package mortal.game.view.task.drama.operations
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.model.vo.pet.*;
    import mortal.game.mvc.*;
    import mortal.game.view.task.drama.*;
    import mortal.mvc.core.*;

    public class TaskDramaOpPetHide extends Object implements ITaskDramaStepCommand
    {
        private var _lastUid:String;

        public function TaskDramaOpPetHide()
        {
            return;
        }// end function

        public function call(param1:TTaskDrama, param2:Function = null) : void
        {
            var callTimeOut:Function;
            var petOutOrInVO:PetOutOrInVO;
            var data:* = param1;
            var callback:* = param2;
            callTimeOut = function () : void
            {
                if (callback != null)
                {
                    callback.apply();
                }
                return;
            }// end function
            ;
            this._lastUid = null;
            var hasFightPet:* = Cache.instance.pet.hasPetFight();
            if (hasFightPet)
            {
                this._lastUid = Cache.instance.pet.fightPetUid;
                petOutOrInVO = new PetOutOrInVO(this._lastUid, EPetState._EPetStateIdle);
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetOutOrIn, petOutOrInVO));
            }
            var time:Number;
            if (TaskDramaOperator.ationTime > 0)
            {
                time = TaskDramaOperator.ationTime;
            }
            setTimeout(callTimeOut, time * 1000);
            return;
        }// end function

        public function cancel(param1:TTaskDrama, param2:Function = null) : void
        {
            var cancelTimeOut:Function;
            var petOutOrInVO:PetOutOrInVO;
            var uid:String;
            var data:* = param1;
            var callback:* = param2;
            cancelTimeOut = function () : void
            {
                if (callback != null)
                {
                    callback.apply();
                }
                return;
            }// end function
            ;
            if (this._lastUid != null)
            {
                petOutOrInVO = new PetOutOrInVO(this._lastUid, EPetState._EPetStateActive);
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetOutOrIn, petOutOrInVO));
            }
            else if (!Cache.instance.pet.hasPetFight())
            {
                uid = Cache.instance.pet.getHighestLevelPetUid();
                if (uid != null && uid != "")
                {
                    petOutOrInVO = new PetOutOrInVO(uid, EPetState._EPetStateActive);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetOutOrIn, petOutOrInVO));
                }
            }
            var time:Number;
            if (TaskDramaOperator.ationTime > 0)
            {
                time = TaskDramaOperator.ationTime;
            }
            setTimeout(cancelTimeOut, time * 1000);
            return;
        }// end function

        public function dispose() : void
        {
            return;
        }// end function

    }
}
